package singleton.v1;

/**
 * 部分代码上锁依然不安全
 * @author wanglong
 * @createDate: 2019年3月24日 下午10:46:15
 */
public class SingletonUnSafe2 {
	
	private static SingletonUnSafe2 object;
	
	private SingletonUnSafe2() {}
	
	private static SingletonUnSafe2 getInstance() {
		try {
			if(object == null) {
				Thread.sleep(3000);
				synchronized (SingletonUnSafe2.class) {
					object = new SingletonUnSafe2();
				}
			}
		} catch (Exception e) {
			e.printStackTrace();
		}
		return object;
	}
	
	
	public static void main(String[] args) {
		for (int i = 0; i < 5; i++) {
			new Thread(new Runnable() {
				
				@Override
				public void run() {
					SingletonUnSafe2 object = SingletonUnSafe2.getInstance();
					System.out.println(object);
				}
			}).start();
		}
	}

}
